<?php
namespace App\Model;

use Illuminate\Support\Facades\DB;

class Keepsake extends BaseModel
{

    protected $connection = 'api';
    protected $table = "rs_couple_keepsake";
    protected $fields = ['id', 'keepsake_name as keepsakeName', 'price', 'upgrade_price as upgradePrice',
        'content', 'head_img_url as headImgUrl', 'rule_img_url as ruleImgUrl', 'decorate_svg as decorateSvg',
        'backgroud_svg as backgroudSvg', 'prop_id as propId', 'level', 'give_prop as giveProp',
        'give_intimate as giveIntimate', 'gift_upper_limit as giftUpperLimit', 'unlock_ring as unlockRing',
        'is_show as isShow', 'is_floating as isFloating'];
    protected $tablePrefix = '';

    public function __construct()
    {
        $this->tablePrefix = env('DB_PREFIX');
    }

    public function getAllKeepsake () {
        $rows = DB::connection($this->connection)
            ->table($this->table)
            ->select($this->fields)
            ->get();
        return $this->objToArray($rows);
    }

    public function getKeepsakeLsit ($offset, $rows) {
        $rows = DB::connection($this->connection)
            ->table($this->table)
            ->where('is_deleted', 0)
            ->select($this->fields)
            ->offset($offset)
            ->limit($rows)
            ->get();
        return $this->objToArray($rows);
    }

    public function getKeepsakeCount () {
        $rows = DB::connection($this->connection)
            ->table($this->table)
            ->where('is_deleted', 0)
            ->count();
        return $this->objToArray($rows);
    }
}
?>